import 'package:flutter/material.dart';
import 'package:library_base/constant/constant.dart';
import 'package:library_base/ext/bool_ext.dart';
import 'package:library_base/ext/double_ext.dart';
import 'package:library_base/entities/stock_out_order_detail_child_entity.dart';
import 'package:library_base/global/multi_language.dart';
import 'package:library_base/res/decoration.dart';
import 'package:library_base/res/gaps.dart';
import 'package:library_base/res/styles.dart';
import 'package:library_base/res/widget_generator.dart';
import 'package:library_base/utils/sp_util.dart';
import 'package:library_base/utils/theme_util.dart';
import 'package:library_base/ext/theme_data_ext.dart';
import 'package:library_base/res/edge.dart';
import 'package:get/get.dart';
import 'package:library_base/widget/button/gradient_button.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:library_base/widget/image/local_image.dart';


Widget buildItem(
  StockOutOrderDetailChildEntity taskEntity,
  int position, {
  Function? onExpand,
  Function(
      StockOutOrderDetailChildEntity taskEntity,
      int position,
      bool enablePreDistributedGoods,
  )? preDistribution,
}) {

  String image = '';
  var enable = false ;
  if(taskEntity.actualOutCount>0.0){
    if(taskEntity.actualOutWeight>0.0){
      image = 'wms_complete';
    }else{
      image = 'wms_allocated';
    }
    enable = true;
  }else if(taskEntity.actualOutWeight>0.0){
    image = 'wms_complete';
    enable = true;
  }else{
    enable = false;
  }

  var enablePreDistributedGoods = taskEntity.actualOutWeight<=0.0 ;

  List<Widget> widgets = [];

  widgets.add(Row(
    crossAxisAlignment: CrossAxisAlignment.start,
    children: [
      Text("${MultiLanguage.productName.tr} : ", style: normalTextColor28),
      Expanded(child: Text(taskEntity.goodsName, style: normalTextColor28)),
    ],
  ));

  widgets.add(gapH18);

  widgets.add(Row(
    children: [
      Text("${MultiLanguage.commodityQuantity.tr} : ", style: normalTextColor28),
      Expanded(child: Text(taskEntity.planOutCount.toString(), style: normalTextColor28)),
    ],
  ));

  widgets.add(gapH18);

  widgets.add(Row(
    children: [
      Text("${MultiLanguage.orderWeight.tr}${SPUtil.isJin.unitStrZhWithBracket()} : ", style: normalTextColor28),
      Expanded(child: Text(taskEntity.planOutWeight.remoteUnitTransitionLocalUnitStr(taskEntity.unit), style: normalTextColor28)),
    ],
  ));
  return roundWidget(
    padding: edgeAll24,
    margin: edgeLR24,
    decoration: rs8,
    child: Stack(
      children: [
        Visibility(
          visible: enable,
          child: Positioned(
              left: 320.w,
              top : 10.w,
              child: image.isNotEmpty?LocalImage(image, package: Constant.packWms(), width: 120.w, height: 120.w):Container()),
        ),
        Row(
          crossAxisAlignment: CrossAxisAlignment.end,
          children: [
            Expanded(
              child: Column(mainAxisSize: MainAxisSize.min, children: widgets),
            ),
            GradientButton(
              ThemeUtil.getTheme(),
              decoration: BoxDecoration(
                  borderRadius: const BorderRadius.all(Radius.circular(20)),
                  border: Border.fromBorderSide(
                      BorderSide(color: ThemeUtil.getTheme().fourthTextColor())),
                  color: ThemeUtil.getTheme().colorScheme.secondary),
              height: 77.w,
              padding: edgeLR24 as EdgeInsets,
              normalColor: ThemeUtil.getTheme().colorScheme.secondary,
              textStyle: textFourthColor26,
              text: enablePreDistributedGoods ? MultiLanguage.preDistributedGoods.tr:MultiLanguage.distributionDetails.tr,
              onPressed: (){
                preDistribution?.call(taskEntity,position,enablePreDistributedGoods);
              },
            )
          ],
        ),
      ],
    ),
  );
}
